import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.Collections;
import java.util.List;

/**
 * @Description: TODO
 * @Author st
 * @Date 2021-12-01 16:36
 */
public class HrReader {
    public void readXml() throws DocumentException {
        String file = "Z:\\Java_camp\\JavaWeb\\XML\\code\\src\\hr.xml";


        SAXReader reader = new SAXReader();
        Document document = reader.read(file);
        Element root = document.getRootElement();
        List<Element> employees = root.elements();
        for(Element employee:employees){
            Element name = employee.element("name");
            String empName = name.getText();
            System.out.println(empName);
            System.out.println(employee.elementText("salary"));
        }
    }

    public static void main(String[] args) {
        HrReader hrReader = new HrReader();
        try {
            hrReader.readXml();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
}
